<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>调度计划</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <script src="/style/public/publicStyle.js"></script>
    <style type="text/css">
        .cardHeader {
            font-weight:bold;
            background-color: #B5FFF8;
            width: 90%;
        }
    </style>

</head>

<body>
<div class="weadmin-nav" style="margin-top: 15px">
			<span class="layui-breadcrumb" style="visibility: visible;">
			<a href="">任务调度管理</a><span lay-separator="">/</span>
			<a>
				<cite>调度中心</cite></a>
			</span>
    <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right;background-color: #1E9FFF"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px;">ဂ</i></a>
</div>
<div class="layui-row">
    <div class="layui-col-md6">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>任务列表</legend>
        </fieldset>
        <div id="jobList"></div>
        <div id="main" class="echarts" style="width:100%;height:400px"></div>
    </div>
    <div class="layui-col-md6">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>执行明细</legend>
        </fieldset>
        <div class="layui-row">
            <table class="layui-hide" id="tableDataList" lay-filter="tableDataList"></table>
        </div>
    </div>
</div>
<div class="layui-collapse" lay-filter="test" id="showDetail" style="display:none;">
</div>
</body>
<script>
    var option = {
        color: [
            '#1E9FFF',
            '#FF5722',
            '#393D49',
            '#FFB800'
        ],
        title:{text:'30天定时任务执行统计'},
        xAxis: {
            type: 'category',
            data: ['01-01','01-02','01-03','01-04','01-05','01-06','01-07','01-08','01-09','01-10','01-11','01-12','01-24', '01-25', '01-26']
        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ['job1', 'job2', 'job3']
        },
        yAxis: {
            type: 'value'
        },
        series: [
            {
                name:'job1',
                data: [0, 0,0,0, 0, 1,1, 0, 0,1, 0, 1,1, 1, 1],
                type: 'line'
            },
            {
                name:'job2',
                data: [0, 1,0,3, 0, 1,4, 0, 0,1, 0, 1,4, 3, 6],
                type: 'line'
            },
            {
                name:'job3',
                data: [10, 20,30,30, 30, 21,21, 0, 0,1, 0, 11,31, 21, 1],
                type: 'line'
            }
        ]
    };
    // console.log(echarts);
    var echartsInstance=echarts.init(document.getElementsByClassName('echarts')[0]);
    //使用echarts对想象的init方法，创建一个二charts实例
    echartsInstance.setOption(option);
    layui.use(['dropdown', 'util', 'laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element'], function () {
        var $ = layui.jquery
            , layer = layui.layer //弹层
            , table = layui.table //表格
            ,element = layui.element;
        table.render({
            elem: '#tableDataList'
            , even: true //开启隔行背景
            , cellMinWidth: 80
            , toolbar: '#toolbarDemo'
            , url: global_visit_url_prefix + '/joblog/pageList'
            , cols: [[
                , {field: 'id', title: 'ID', hide: true}
                , {field: 'executorHandler', title: '执行器'}
                , {field: 'handleTime', title: '执行时间', templet: '<div>{{layui.util.toDateString(d.handleTime, \'yyyy-MM-dd HH:mm:ss\')}}</div>'}
                , {field: 'handleCode', title: '执行结果',width:100,templet: function(d){
                    if(d.handleCode=="200") {
                        return "成功";
                    } else if(d.handleCode=="0") {
                        return "执行中";
                    } else {
                        return "<font style=\"color: #ff1717;\">失败</font>";
                    }
                  }}
                , {fixed: 'right', title: '操作', align: 'center', toolbar: '#op', width: 69}
            ]],
            done: {}
            , page: true
        });
        table.on('tool(tableDataList)', function (obj) {
            var item = obj.data;
            if (obj.event === 'showDetail') {
                debugger;
                $.ajax({
                    url: '/job/etlGroupBatch/findJobExecutionByIdGroup',
                    type: 'get',
                    data: {"idGroup":item.id},
                    success: function (data1) {
                        var data = data1.data;
                        var html = "";
                        $.each(data,function (index,item) {
                            html += '<div class="layui-colla-item">\n' +
                                '    <h2 class="layui-colla-title" idJobException="'+item.id+'">'+item.id+':'+item.status+'('+item.startDate+'~'+item.endDate+' 累计耗时'+item.times+'秒)'+'</h2>\n' +
                                '    <div class="layui-colla-content">\n' +
                                '      <p>'+item.errorMsg+'</p>\n' +
                                '      <table class="layui-table" name="stepTable"><thead><tr><th>步骤名称</th><th>状态</th><th>读取条数</th><th>写入条数</th><th>跳过条数</th></tr></thead><tbody></tbody></table>\n' +
                                '    </div>\n' +
                                '  </div>';
                        });
                        $("#showDetail").html(html);
                        element.render();
                        layer.open({
                            //layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
                            type: 1,
                            title: item.des,
                            area: ['1024px', '700px'],
                            content: $("#showDetail")//引用的弹出层的页面层的方式加载修改界面表单
                        });
                    }
                });

            }
        });
        //监听折叠
        element.on('collapse(test)', function(data){
            var tbody = $(this).parent().find("table[name='stepTable']").find("tbody");
            if(tbody.html()!="") {
                return ;
            }
            var html="";
            $.ajax({
                url: '/job/etlGroupBatch/findStepExecutionByIdJob',
                type: 'get',
                async: false,
                data: {"idJobException":$(this).attr("idJobException")},
                success: function (data1) {
                    var data = data1.data;
                    $.each(data,function (index,item) {
                        html+="<tr><td>"+item.stepName+"</td><td>"+item.status+"</td><td>"+item.readCount+"</td><td>"+item.writeCount+"</td><td>"+item.skipCount+"</td></tr>"
                    });
                    $(this).parent().find("table[name='stepTable']").find("tbody").html(html);
                }
            });
            tbody.html(html);
        });
        var color = ["red","green","black"];
        var job24hTrigger = function (data) {

            $.ajax({
                url:'/jobinfo/triggerTime24h',
                type:'post',
                dataType:'json',
                contentType:'application/json;charset=UTF-8',
                data:JSON.stringify(data),
                success:function (msg) {
                    $("#jobList24h").empty();
                    var data = msg.data;
                    var html = "";
                    var job;
                    var i=0;
                    for (var key in data) {
                        i++;
                        job = data[key];
                        html += job.jobname+'('+job.nextTimeDesc+'后 剩余'+job.times+'次)<hr class="layui-border-'+color[i%3]+'"><br>';
                    }
                    $("#jobList24h").append(html);
                }
            })
        }
        function refash() {
            $.ajax({
                type: "get",
                url: " /jobplan/getPlanData",
                async: true,
                success: function (msg) {
                    $("#jobList").empty();
                    layui.layer.closeAll()
                    var data = msg.data;
                    var xxlJobHtml = "";
                    var job,status ;
                    var jobDataArr = [],jobData;
                    var i=0;
                    for (var key in data) {
                        if(i<data.length) {
                            job = data[key];
                            if (i % 2 == 0) {
                                xxlJobHtml += '<div class="layui-row">';
                            }//triggerStatus
                            status = job.triggerStatus == 1 ? '<span style="color:#00FF00;float: right; ">Runing</span>':'<span style="color: #ff0907;float: right;">Stop</span>';
                            xxlJobHtml += '<div class="layui-col-md6">' +
                                '<div class="layui-card">' +
                                '<div class="layui-card-header cardHeader" style="background-color:#1E9FFF;color: #fff">'+job.jobDesc+status+'</div>' +
                                '<div class="layui-card-body">' +
                                '待处理异常数：<span style="color: red">'+job.id+'个</span><br/><br/>' +
                                '执行频次('+job.scheduleConf+')<br/><br/>' +
                                '下次执行时间：'+job.triggerNextTime+'<br/><br/>' +
                                '</div>' +
                                '</div>' +
                                '</div>';
                            if (i % 2 == 1) {
                                xxlJobHtml += '</div>';
                            }
                            if(job.triggerStatus == 1) {
                                jobData = new Object();
                                jobData.cron = job.scheduleConf;
                                jobData.jobDesc = job.jobDesc;
                                jobDataArr.push(jobData);
                            }
                        }
                        i++;
                    }
                    $("#jobList").append(xxlJobHtml);
                    job24hTrigger(jobDataArr);
                }
            });
        }
        refash();
    });

</script>
<script type="text/html" id="op">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="showDetail">详情</a>
</script>
</html>